import 'package:flutter/material.dart';
import 'package:lifecycle/lifecycle.dart';
import 'package:people_big_people/route/route_map.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:people_big_people/route/route_ob.dart';
import 'package:people_big_people/utils/event_bus_utils.dart';
///全局key
final GlobalKey<NavigatorState> applicationKey = GlobalKey<NavigatorState>();

class App extends StatelessWidget {
  const App({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return const AppPage(title: 'Flutter Demo Home Page');
  }
}

class AppPage extends StatefulWidget {
  const AppPage({Key? key, required this.title}) : super(key: key);

  final String title;

  @override
  State<AppPage> createState() => _AppPageState();
}

class _AppPageState extends State<AppPage> {
  MyRouteObserver<PageRoute> myRouteObserver = MyRouteObserver<PageRoute>();

  @override
  void initState() {
    super.initState();
  }

  @override
  void dispose() {
    super.dispose();
    EventBusUtils.instance.destroy();
  }

  @override
  Widget build(BuildContext context) {
    return Localizations(
      locale: const Locale("zh"),
      delegates: const [
        GlobalMaterialLocalizations.delegate, //Android
        GlobalWidgetsLocalizations.delegate,
        GlobalCupertinoLocalizations.delegate, //IOS
      ],
      child: Directionality(
        textDirection: TextDirection.ltr,
        child: MaterialApp(
          navigatorKey: applicationKey,
          themeMode: ThemeMode.system,
          // navigatorObservers: [myRouteObserver],
          navigatorObservers: [defaultLifecycleObserver],
          initialRoute: router.desktop.routeName,
          onGenerateRoute: onGenerateRoute,
          debugShowCheckedModeBanner: false,
          builder: (context, child) {
            return MediaQuery(
                data: const MediaQueryData(
                  textScaleFactor: 1.0,
                ),
                child: child!);
          },
        ),
      ),
    );
  }
}
